package club.laowang.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < 10000000; i ++) {
                sb.append("Hello World" + i);
            }
            return sb.toString();
        });
        completableFuture.thenAccept((msg) -> {
            System.out.println(msg);
        });

        System.out.println("我先输出");
        completableFuture.join();
    }
}
